package com.bw.controller;

import com.alibaba.fastjson.JSONObject;
import com.bw.pojo.Goods;
import com.bw.pojo.vo.GoodsVo;
import com.bw.service.impl.GoodsServiceImpl;
import com.bw.util.PageResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/goodschange/*")
public class GoodsChangeController extends BaseController{
    GoodsServiceImpl service = new GoodsServiceImpl();
    //查看
    protected void getGoodsList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接收参数 2.将json转对象 3.将对象丢给Service 4.响应用户
        String reqInfos = req.getParameter("reqInfos");
        GoodsVo goodsVo = JSONObject.parseObject(reqInfos, GoodsVo.class);
//        //返回 分页工具类对象
//        PageResult<GoodsVo> list = service.getGoodsList(goodsVo);
//        resp.getWriter().println(JSONObject.toJSONString(list));
    }
    //删除
    protected void getToDel(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接收参数 2.将json转对象 3.将对象丢给Service 4.响应用户
        String reqInfos = req.getParameter("reqInfos");
        GoodsVo goodsVo = JSONObject.parseObject(reqInfos, GoodsVo.class);
//        service.getToDel(goodsVo);
//        resp.getWriter().println(JSONObject.toJSONString(200));
    }
    //回显
    protected void findById(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String reqInfos = req.getParameter("reqInfos");
        GoodsVo goodsVo = JSONObject.parseObject(reqInfos, GoodsVo.class);
        GoodsVo g = service.findById(goodsVo);
        resp.getWriter().println(JSONObject.toJSONString(g));
    }
    //添加
    protected void getAdd(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String reqInfos = req.getParameter("reqInfos");
        Goods goods = JSONObject.parseObject(reqInfos, Goods.class);
        service.getAdd(goods);
        resp.getWriter().println(JSONObject.toJSONString(200));
    }
    //修改
    //修改
    protected void getUpd(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String reqInfos = req.getParameter("reqInfos");
        Goods goods = JSONObject.parseObject(reqInfos, Goods.class);
        service.getUpd(goods);
        resp.getWriter().println(JSONObject.toJSONString(200));
    }
}
